package net.mingsoft.base.biz.impl;

import com.baomidou.mybatisplus.core.mapper.*;
import com.baomidou.mybatisplus.extension.service.impl.*;
import net.mingsoft.base.biz.*;
import org.slf4j.*;
import net.mingsoft.base.entity.*;
import java.util.*;
import net.mingsoft.base.util.*;
import net.mingsoft.base.dao.*;
import com.baomidou.mybatisplus.core.conditions.*;

public abstract class BaseBizImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements IBaseBiz<T>
{
    protected final Logger LOG;
    
    public BaseBizImpl() {
        this.LOG = LoggerFactory.getLogger((Class)this.getClass());
    }
    
    public int saveEntity(final BaseEntity entity) {
        return this.getDao().saveEntity(entity);
    }
    
    public void deleteEntity(final int id) {
        this.getDao().deleteEntity(id);
    }
    
    public void updateEntity(final BaseEntity entity) {
        this.getDao().updateEntity(entity);
    }
    
    public List<T> queryAll() {
        return this.getDao().queryAll();
    }
    
    @Deprecated
    public int queryCount() {
        return this.getDao().queryCount();
    }
    
    public BaseEntity getEntity(final int id) {
        return this.getDao().getEntity(id);
    }
    
    public List queryBySQL(final String table, final List fields, final Map wheres, final Integer begin, final Integer end) {
        SqlInjectionUtil.filterContent(table);
        return this.getDao().queryBySQL(table, fields, wheres, null, begin, end, null, null);
    }
    
    public int countBySQL(final String table, final Map wheres) {
        SqlInjectionUtil.filterContent(table);
        return this.getDao().countBySQL(table, wheres, null);
    }
    
    public int countBySQL(final String table, final Map wheres, final List<Map> sqlWhereList) {
        SqlInjectionUtil.filterContent(table);
        if (sqlWhereList != null) {
            sqlWhereList.forEach(map -> SqlInjectionUtil.filterContent(map.get("field") + ""));
        }
        return this.getDao().countBySQL(table, wheres, sqlWhereList);
    }
    
    public List queryBySQL(final String table, final List fields, final Map wheres) {
        SqlInjectionUtil.filterContent(table);
        return this.getDao().queryBySQL(table, fields, wheres, null, null, null, null, null);
    }
    
    public List queryBySQL(final String table, final List<String> fields, final Map wheres, final List<Map> sqlWhereList) {
        SqlInjectionUtil.filterContent(table);
        if (sqlWhereList != null) {
            sqlWhereList.forEach(map -> SqlInjectionUtil.filterContent(map.get("field") + ""));
        }
        return this.getDao().queryBySQL(table, fields, wheres, sqlWhereList, null, null, null, null);
    }
    
    public List queryBySQL(final String table, final List<String> fields, final Map wheres, final List<Map> sqlWhereList, final Integer begin, final Integer end) {
        SqlInjectionUtil.filterContent(table);
        if (sqlWhereList != null) {
            sqlWhereList.forEach(map -> SqlInjectionUtil.filterContent(map.get("field") + ""));
        }
        return this.getDao().queryBySQL(table, fields, wheres, sqlWhereList, begin, end, null, null);
    }
    
    public List queryBySQL(final String table, final List<String> fields, final Map wheres, final List<Map> sqlWhereList, final String orderBy, final String order) {
        SqlInjectionUtil.filterContent(table);
        if (sqlWhereList != null) {
            sqlWhereList.forEach(map -> SqlInjectionUtil.filterContent(map.get("field") + ""));
        }
        return this.getDao().queryBySQL(table, fields, wheres, sqlWhereList, null, null, orderBy, order);
    }
    
    public List queryBySQL(final String table, final List<String> fields, final Map wheres, final List<Map> sqlWhereList, final Integer begin, final Integer end, final String orderBy, final String order) {
        SqlInjectionUtil.filterContent(table);
        if (sqlWhereList != null) {
            sqlWhereList.forEach(map -> SqlInjectionUtil.filterContent(map.get("field") + ""));
        }
        return this.getDao().queryBySQL(table, fields, wheres, sqlWhereList, begin, end, orderBy, order);
    }
    
    public void updateBySQL(final String table, final Map fields, final Map wheres) {
        SqlInjectionUtil.filterContent(table);
        this.getDao().updateBySQL(table, fields, wheres);
    }
    
    public void deleteBySQL(final String table, final Map wheres) {
        SqlInjectionUtil.filterContent(table);
        this.getDao().deleteBySQL(table, wheres);
    }
    
    public void insertBySQL(final String table, final Map fields) {
        SqlInjectionUtil.filterContent(table);
        this.getDao().insertBySQL(table, fields);
    }
    
    public void createTable(final String table, final Map fileds) {
        SqlInjectionUtil.filterContent(table);
        this.getDao().createTable(table, fileds);
    }
    
    public void dropTable(final String table) {
        SqlInjectionUtil.filterContent(table);
        this.getDao().dropTable(table);
    }
    
    public Object excuteSql(final String sql) {
        return this.getDao().excuteSql(sql);
    }
    
    public void alterTable(final String table, final Map fileds, final String type) {
        SqlInjectionUtil.filterContent(table);
        this.getDao().alterTable(table, fileds, type);
    }
    
    protected abstract IBaseDao<T> getDao();
    
    public void saveBatch(final List list) {
        this.getDao().saveBatch(list);
    }
    
    public void updateCache() {
        this.getDao().updateCache();
    }
    
    public void delete(final int[] ids) {
        this.getDao().delete(ids);
    }
    
    public void delete(final String[] ids) {
        this.getDao().delete(ids);
    }
    
    public void deleteEntity(final BaseEntity entity) {
        this.getDao().deleteByEntity(entity);
    }
    
    public T getEntity(final BaseEntity entity) {
        return this.getDao().getByEntity(entity);
    }
    
    public List<T> query(final BaseEntity entity) {
        return this.getDao().query(entity);
    }
    
    public T getOne(final Wrapper<T> queryWrapper, final boolean throwEx) {
        return (T)super.getOne((Wrapper)queryWrapper, throwEx);
    }
}
